INTERSIM ?= intersim2
SIM_OBJ_FILES_DIR ?= ./build

CPP = g++

CXXFLAGS = -O0 -g
CSRCS = $(shell ls *.cpp)
INTERSIMOBJS = $(shell ls intersim2/obj/*.o)
OUTPUT_DIR ?= ./build

OBJS=$(CSRCS:%.cpp=%.o)
COBJS=$(OBJS:%.o=$(OUTPUT_DIR)/%.o)

RAMULATOR_CSRCS = $(shell ls ./ramulator/*.cc)
RAMULATOR_OBJS=$(RAMULATOR_CSRCS:%.cc=%.o)
RAMULATOR_COBJS=$(RAMULATOR_OBJS:%.o=$(OUTPUT_DIR)/%.o)


simulator: $(OBJS)  $(RAMULATOR_OBJS)
	$(CPP) $(CXXFLAGS)  $(COBJS) $(RAMULATOR_COBJS)  $(INTERSIMOBJS) -o $@

$(OBJS):%.o:%.cpp
	$(CPP) $(CXXFLAGS) -c $< -o $(OUTPUT_DIR)/$@

$(RAMULATOR_OBJS):%.o:%.cc
	$(CPP) $(CXXFLAGS) -c $< -o $(OUTPUT_DIR)/$@

intersim2: makedirs
	$(MAKE) "CREATE_LIBRARY=1" "DEBUG=$(DEBUG)" -C ./intersim2

clean:
	rm -f $(COBJS)